package com.xsy.android.compose.wandroid.ui.page.project

import android.app.Application
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import com.xsy.android.compose.wandroid.logic.base.paging.OfficialPagingSource
import com.xsy.android.compose.wandroid.logic.base.paging.ProjectPagingSource
import com.xsy.android.compose.wandroid.logic.base.repository.BaseArticleRepository
import com.xsy.android.compose.wandroid.logic.model.ArticleModel
import com.xsy.android.compose.wandroid.logic.model.BaseModel
import com.xsy.android.compose.wandroid.logic.model.ClassifyModel
import com.xsy.android.compose.wandroid.logic.model.Query
import com.xsy.android.compose.wandroid.logic.network.Network
import kotlinx.coroutines.flow.Flow

class OfficialRepository(val app: Application) : BaseArticleRepository(app = app) {
    override suspend fun getArticleTree(): BaseModel<List<ClassifyModel>> {
        return Network.getWxArticleTree()
    }

    override fun getPagingData(query: Query): Flow<PagingData<ArticleModel>> = Pager(
        PagingConfig(
            pageSize = PAGE_SIZE,
            enablePlaceholders = false
        )
    ) {
        OfficialPagingSource(query.cid)
    }.flow

}